"""
Frame for retrieving the data.
All input frame must inherit from this frame
and override the corresponding methods.
"""

import tkinter as tk
import tkinter.messagebox as messagebox

class DataProvidingFrame(tk.Frame):
    """The frames in the data selection frame should inherit from this.
    
    This method primarly provides"""
    def getDataGenerator(self):
        """Returns a bit generator yielding the data to CRC.

        Returns None if no data was entered."""
        raise NotImplementedError(
            "This function must be overriden in a subclass.")
    def dataGeneratorReady(self):
        """Returns True if the data is ready to be CRCed.

        This method should not necessarily be implemented, its default
        behaviour is to check if getDataGenerator returns None."""
        return  self.getDataGenerator() is not None
    def getDataSize(self):
        """Returns the size of the data."""
        raise NotImplementedError(
            "This function must be overriden in a subclass.")
    def get_help_message(self):
        """Display a help message when clicking on the help button."""
        raise NotImplementedError(
            "This function must be overriden in a subclass.")
    def create_help_button(self):
        """Create the help button."""
        def display_help():
            messagebox.showinfo('Help', self.get_help_message())
        self.help_button = tk.Button(self, text='?', command=display_help)
        self.help_button.place(in_=self,anchor=tk.N+tk.E,relx=1,x=-5, y=5)

    def create_widgets(self):
        self.create_help_button()

    def __init__(self,master=None,size=(100,100)):
        super().__init__(master)
        self.verboseModeAllowed = 1
        self.grid_propagate(0) # Disables geometry propagation.
        self.propagate(0)
        # Prevent the frame overlapping the border.
        self["width"] = str(size[0]-6)
        self["height"] = str(size[1]-6)
        self["relief"] = "groove"
        self["borderwidth"] = "3"